import {defineStore} from "pinia";
import {ref} from "vue";
import {getUserId} from "@/util/LocalUtils.js";
import {reqUserInfo} from "@/api/index.js";

const useUserStore = defineStore("currUser", () => {
    const currUser = ref({})

    async function init() {
        const userId = Number(getUserId())
        const userInfo = await reqUserInfo()
        currUser.value = {userId, avatarUrl: userInfo.data.avatarUrl}
    }

    return {
        currUser,
        init
    }
})

export default useUserStore